package wyx240407;

public class Day03 {
    static String[] history=new String[100];
    static String[] winHistory=new String[100];
    static int winCount=0;
    static int count=0;
    static int num;
    static int front;
    static int rear;
    public Day03(){
        if(count==0) {
            history[count++] = "游戏开始！";
            front = 1;
            rear = 100;
            setNum();
        }
    }

    public String getWinHistory(int i) {
        return winHistory[i];
    }

    public int getWinCount() {
        return winCount;
    }

    private void setNum(){
        num=(int)(Math.random()*(rear-front+1)+front);
    }

    public int getFront() {
        return front;
    }

    public int getRear() {
        return rear;
    }

    public String getHistory(int i) {
        return history[i];
    }
    public int getCount() {
        return count;
    }

    public boolean guess(int useNum){
        if(useNum< num){
            front=Math.max(useNum+1, front);
            history[count]="第"+count++ +"次猜"+useNum+"，猜小了！";
            return false;
        }else if(useNum> num){
            rear=Math.min(useNum-1, rear);
            history[count]="第"+count++ +"次猜"+useNum+"，猜大了！";
            return false;
        }else{
            winHistory[winCount++]="第"+(winCount+1)+"轮在第"+count +"次猜对！";
            history[count]="第"+count++ +"次猜"+useNum+"猜对了！";
            return true;
        }
    }
    public void clear(){
        count=0;
        front=0;
        rear=0;
        setNum();
    }

}
